package com.ruoyi.project.business.controller;

import java.util.List;

import com.ruoyi.project.business.domain.BusinessFarmServiceOrder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.service.IBusinessFarmServiceOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 农田服务订单Controller
 * 
 * @author ruoyi
 * @date 2020-10-22
 */
@RestController
@RequestMapping("/business/serviceorder")
public class BusinessFarmServiceOrderController extends BaseController
{
    @Autowired
    private IBusinessFarmServiceOrderService businessFarmServiceOrderService;

    /**
     * 查询农田服务订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessFarmServiceOrder businessFarmServiceOrder)
    {
        startPage();
        List<BusinessFarmServiceOrder> list = businessFarmServiceOrderService.selectBusinessFarmServiceOrderList(businessFarmServiceOrder);
        return getDataTable(list);
    }

    /**
     * 导出农田服务订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:export')")
    @Log(title = "农田服务订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessFarmServiceOrder businessFarmServiceOrder)
    {
        List<BusinessFarmServiceOrder> list = businessFarmServiceOrderService.selectBusinessFarmServiceOrderList(businessFarmServiceOrder);
        ExcelUtil<BusinessFarmServiceOrder> util = new ExcelUtil<BusinessFarmServiceOrder>(BusinessFarmServiceOrder.class);
        return util.exportExcel(list, "serviceorder");
    }

    /**
     * 获取农田服务订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessFarmServiceOrderService.selectBusinessFarmServiceOrderById(id));
    }

    /**
     * 新增农田服务订单
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:add')")
    @Log(title = "农田服务订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessFarmServiceOrder businessFarmServiceOrder)
    {
        return toAjax(businessFarmServiceOrderService.insertBusinessFarmServiceOrder(businessFarmServiceOrder));
    }

    /**
     * 修改农田服务订单
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:edit')")
    @Log(title = "农田服务订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessFarmServiceOrder businessFarmServiceOrder)
    {
        return toAjax(businessFarmServiceOrderService.updateBusinessFarmServiceOrder(businessFarmServiceOrder));
    }

    /**
     * 删除农田服务订单
     */
    @PreAuthorize("@ss.hasPermi('business:serviceorder:remove')")
    @Log(title = "农田服务订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessFarmServiceOrderService.deleteBusinessFarmServiceOrderByIds(ids));
    }
}